import { useUserStore } from "@/pinia/modules/user";

export const myRouter = (url,isRedirectTo)=>{
    const userStore = useUserStore()
    const token = userStore.token || ''
    const blackList = []
	
	const loginList = ['/pages/user/login','/pages/user/register']
    const inBlack = blackList.some(b=>{
        return url.indexOf(b) > -1
    })
	
	const inLogin = loginList.some(b=>{
        return url.indexOf(b) > -1
    })

	if(inLogin && token) {
	    uni.redirectTo({
	        url: '/pages/home/index'
	    })
	    return
	}
	
    if(inBlack && !token) {
        uni.redirectTo({
            url: '/pages/home/index'
        })
        return
    }
   
	if (isRedirectTo){
		uni.redirectTo({
			url: url
		})
		return	
	}
	uni.navigateTo({
	    url: url
	})
}